﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Services;
using Entities;
using WebUI.Models;

namespace WebUI.Controllers
{
    public partial class DetailsController : Controller
    {
        #region Member Variables

        readonly IDetailsService detailsService;
        readonly FilterOperations filter;

        #endregion

        #region Constructor

        public DetailsController(IDetailsService detailsService, FilterOperations filter)
        {
            this.detailsService = detailsService;
            this.filter = filter;
        }

        #endregion

        #region Action Methods

        public virtual ViewResult FileDetails(string objectName)
        {
            ViewBag.Name = Resources.FileDetailsTitle;
            ViewBag.FileName = objectName;
            var model = new FilesModel(filter);
            model.FilesList = detailsService.GetFileActions(objectName, filter);
            return View(model);
        }

        [HttpPost]
        [ActionName("FileDetails")]
        public virtual PartialViewResult FilterFileDetails(string File, FormCollection formCollection)
        {
            Common.PopulateFilter(formCollection, filter);
            var results = detailsService.GetFileActions(File, filter);
            return PartialView(MVC.Details.Views._FileDetailsGrid, results);
        }

        public virtual ViewResult UserDetails(string UserName)
        {
            ViewBag.UserName = UserName;
            ViewBag.Name = Resources.UserDetailsTitle;
            var model = detailsService.GetUserActions(UserName, filter);
            model.Filter = filter;
            return View(model);
        }

        #endregion
    }
}